package com.shioirikukuri.controller;

import com.shioirikukuri.entity.DiningTable;
import com.shioirikukuri.service.IDiningTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/dining-tables")
public class DiningTableController {

	@Autowired
	private IDiningTableService diningTableService;

	/**
	 * 获取所有桌位信息
	 *
	 * @return 桌位列表
	 */
	@GetMapping
	public List<DiningTable> getAllDiningTables() {
		return diningTableService.getAllDiningTables();
	}

	/**
	 * 根据桌位ID查询桌位信息
	 *
	 * @param tableId 桌位ID
	 * @return 匹配的桌位对象
	 */
	@GetMapping("/{tableId}")
	public DiningTable getDiningTableById(@PathVariable Long tableId) {
		return diningTableService.getDiningTableById(tableId);
	}


	/**
	 * 新增桌位信息
	 *
	 * @param diningTable 新桌位的信息
	 */
	@PostMapping
	public void createDiningTable(@RequestBody DiningTable diningTable) {
		diningTableService.createDiningTable(diningTable);
	}

	/**
	 * 更新桌位信息
	 *
	 * @param tableId     桌位ID
	 * @param diningTable 需要更新的桌位信息
	 */
	@PutMapping("/{tableId}")
	public void updateDiningTable(@PathVariable Long tableId, @RequestBody DiningTable diningTable) {
		diningTable.setTableId(tableId);
		diningTableService.updateDiningTable(diningTable);
	}

	/**
	 * 删除桌位信息
	 *
	 * @param tableId 桌位ID
	 */
	@DeleteMapping("/{tableId}")
	public void deleteDiningTableById(@PathVariable Long tableId) {
		diningTableService.deleteDiningTableById(tableId);
	}
}